<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/* nodeutil-1.0.2 (c) 2015-2021 Kenji Urushima | kjur.github.io/jsrsasign/license
<span class='line'>  2</span>  */</span><span class="WHIT">
<span class='line'>  3</span> </span><span class="COMM">/*
<span class='line'>  4</span>  * nodeutil.js - Utilities for Node
<span class='line'>  5</span>  *
<span class='line'>  6</span>  * Copyright (c) 2015-2021 Kenji Urushima (kenji.urushima@gmail.com)
<span class='line'>  7</span>  *
<span class='line'>  8</span>  * This software is licensed under the terms of the MIT License.
<span class='line'>  9</span>  * https://kjur.github.io/jsrsasign/license/
<span class='line'> 10</span>  *
<span class='line'> 11</span>  * The above copyright and license notice shall be 
<span class='line'> 12</span>  * included in all copies or substantial portions of the Software.
<span class='line'> 13</span>  */</span><span class="WHIT">
<span class='line'> 14</span> 
<span class='line'> 15</span> </span><span class="COMM">/**
<span class='line'> 16</span>  * @fileOverview
<span class='line'> 17</span>  * @name nodeutil-1.0.js
<span class='line'> 18</span>  * @author Kenji Urushima kenji.urushima@gmail.com
<span class='line'> 19</span>  * @version jsrsasign-util 1.0.3 nodeutil 1.0.2 (2021-Feb-15)
<span class='line'> 20</span>  * @since jsrsasign 5.0.2
<span class='line'> 21</span>  * @license &lt;a href="https://kjur.github.io/jsrsasign/license/">MIT License&lt;/a>
<span class='line'> 22</span>  */</span><span class="WHIT">
<span class='line'> 23</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">"fs"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 24</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">JSONC</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">"jsonc-parser"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 25</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">"jsrsasign"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 26</span> 
<span class='line'> 27</span> </span><span class="COMM">/**
<span class='line'> 28</span>  * read file and return file contents as utf-8 string
<span class='line'> 29</span>  * @param {String} utf8File file name to be read
<span class='line'> 30</span>  * @return {String} utf-8 string of file contents
<span class='line'> 31</span>  * @description
<span class='line'> 32</span>  * This function only works in Node.js.
<span class='line'> 33</span>  */</span><span class="WHIT">
<span class='line'> 34</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">readFileUTF8</span><span class="PUNC">(</span><span class="NAME">utf8File</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 35</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">'fs'</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">readFileSync</span><span class="PUNC">(</span><span class="NAME">utf8File</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'utf8'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 36</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 37</span> 
<span class='line'> 38</span> </span><span class="COMM">/**
<span class='line'> 39</span>  * read binary file and return file contents as hexadecimal string
<span class='line'> 40</span>  * @param {String} binFile file name to be read
<span class='line'> 41</span>  * @return {String} hexadecimal string of file contents
<span class='line'> 42</span>  * @description
<span class='line'> 43</span>  * This function only works in Node.js.
<span class='line'> 44</span>  */</span><span class="WHIT">
<span class='line'> 45</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">readFileHexByBin</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 46</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rs.rstrtohex</span><span class="PUNC">(</span><span class="NAME">fs.readFileSync</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'binary'</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 48</span> 
<span class='line'> 49</span> </span><span class="COMM">/**
<span class='line'> 50</span>  * read file and return file contents
<span class='line'> 51</span>  * @param {String} binFile file name to be read
<span class='line'> 52</span>  * @return {String} raw string of file contents
<span class='line'> 53</span>  * @description
<span class='line'> 54</span>  * This function only works in Node.js.
<span class='line'> 55</span>  */</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">readFile</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 57</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">fs.readFileSync</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'binary'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 58</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 59</span> 
<span class='line'> 60</span> </span><span class="COMM">/**
<span class='line'> 61</span>  * save raw string to file
<span class='line'> 62</span>  * @param {String} binFile file name to save contents.
<span class='line'> 63</span>  * @param {String} rawString string contents to be saved.
<span class='line'> 64</span>  * @description
<span class='line'> 65</span>  * This function only works in Node.js.
<span class='line'> 66</span>  */</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">saveFile</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">rawString</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">'fs'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 69</span> </span><span class="WHIT">    </span><span class="NAME">fs.writeFileSync</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">rawString</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'binary'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 70</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 71</span> 
<span class='line'> 72</span> </span><span class="COMM">/**
<span class='line'> 73</span>  * save UTF-8 string to file
<span class='line'> 74</span>  * @param {String} binFile file name to save contents.
<span class='line'> 75</span>  * @param {String} utf8String string contents to be saved.
<span class='line'> 76</span>  * @description
<span class='line'> 77</span>  * This function only works in Node.js.
<span class='line'> 78</span>  */</span><span class="WHIT">
<span class='line'> 79</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">saveFileUTF8</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">utf8String</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 80</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">'fs'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 81</span> </span><span class="WHIT">    </span><span class="NAME">fs.writeFileSync</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">utf8String</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'utf8'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 82</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 83</span> 
<span class='line'> 84</span> </span><span class="COMM">/**
<span class='line'> 85</span>  * save data represented by hexadecimal string to file
<span class='line'> 86</span>  * @param {String} binFile file name to save contents.
<span class='line'> 87</span>  * @param {String} hexString hexadecimal string to be saved.
<span class='line'> 88</span>  * @description
<span class='line'> 89</span>  * This function only works in Node.js.
<span class='line'> 90</span>  */</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">saveFileBinByHex</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">hexString</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rawString</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">rs.hextorstr</span><span class="PUNC">(</span><span class="NAME">hexString</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT">    </span><span class="NAME">fs.writeFileSync</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">rawString</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'binary'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 94</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 95</span> 
<span class='line'> 96</span> </span><span class="COMM">/**
<span class='line'> 97</span>  * read JSON file and return its JSON object
<span class='line'> 98</span>  * @param {String} JSON file name to be read
<span class='line'> 99</span>  * @return {Object} JSON object or array of file contents
<span class='line'>100</span>  * @since jsrsasign-util 1.0.1 nodeutil 1.0.1
<span class='line'>101</span>  *
<span class='line'>102</span>  * @description
<span class='line'>103</span>  * This function only works in Node.js.
<span class='line'>104</span>  * @example
<span class='line'>105</span>  * var rsu = require("jsrsasign-util");
<span class='line'>106</span>  * rsu.readJSON("aaa.json") &rarr; JSON object
<span class='line'>107</span>  */</span><span class="WHIT">
<span class='line'>108</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">readJSON</span><span class="PUNC">(</span><span class="NAME">jsonFile</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>109</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">jsonStr</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">fs.readFileSync</span><span class="PUNC">(</span><span class="NAME">jsonFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"utf8"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>110</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">json</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">JSON.parse</span><span class="PUNC">(</span><span class="NAME">jsonStr</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>111</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">json</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>112</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>113</span> 
<span class='line'>114</span> </span><span class="COMM">/**
<span class='line'>115</span>  * read JSONC file and return its JSON object
<span class='line'>116</span>  * @param {String} JSONC file name to be read
<span class='line'>117</span>  * @return {Object} JSON object or array of file contents
<span class='line'>118</span>  * @since jsrsasign-util 1.0.1 nodeutil 1.0.1
<span class='line'>119</span>  *
<span class='line'>120</span>  * @description
<span class='line'>121</span>  * This method read JSONC (i.e. JSON with comments) file
<span class='line'>122</span>  * and returns JSON object.
<span class='line'>123</span>  * This function only works in Node.js.
<span class='line'>124</span>  * 
<span class='line'>125</span>  * @example
<span class='line'>126</span>  * var rsu = require("jsrsasign-util");
<span class='line'>127</span>  * rsu.readJSONC("aaa.jsonc") &rarr; JSON object
<span class='line'>128</span>  */</span><span class="WHIT">
<span class='line'>129</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">readJSONC</span><span class="PUNC">(</span><span class="NAME">jsonFile</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>130</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">jsonStr</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">fs.readFileSync</span><span class="PUNC">(</span><span class="NAME">jsonFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"utf8"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>131</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">json</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">JSONC.parse</span><span class="PUNC">(</span><span class="NAME">jsonStr</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>132</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">json</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>133</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>134</span> 
<span class='line'>135</span> </span><span class="COMM">/**
<span class='line'>136</span>  * save JSON object as file
<span class='line'>137</span>  * @param {Object} jsonFile output JSON file name
<span class='line'>138</span>  * @param {Object} json JSON object to save
<span class='line'>139</span>  * @since jsrsasign-util 1.0.1 nodeutil 1.0.1
<span class='line'>140</span>  *
<span class='line'>141</span>  * @description
<span class='line'>142</span>  * This method saves JSON object as a file.
<span class='line'>143</span>  * This function only works in Node.js.
<span class='line'>144</span>  * 
<span class='line'>145</span>  * @example
<span class='line'>146</span>  * var rsu = require("jsrsasign-util");
<span class='line'>147</span>  * rsu.saveFileJSON("aaa.jsonc", json);
<span class='line'>148</span>  */</span><span class="WHIT">
<span class='line'>149</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">saveFileJSON</span><span class="PUNC">(</span><span class="NAME">jsonFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">json</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>150</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">JSON.stringify</span><span class="PUNC">(</span><span class="NAME">json</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"  "</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>151</span> </span><span class="WHIT">    </span><span class="NAME">saveFileUTF8</span><span class="PUNC">(</span><span class="NAME">jsonFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>152</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>153</span> 
<span class='line'>154</span> </span><span class="COMM">/**
<span class='line'>155</span>  * output JSON object to console
<span class='line'>156</span>  * @param {Object} json JSON object to print out
<span class='line'>157</span>  * @param {Object} prefix prefix string (OPTION)
<span class='line'>158</span>  * @since jsrsasign-util 1.0.1 nodeutil 1.0.1
<span class='line'>159</span>  *
<span class='line'>160</span>  * @description
<span class='line'>161</span>  * This method writes JSON object to console.
<span class='line'>162</span>  * This function only works in Node.js.
<span class='line'>163</span>  * 
<span class='line'>164</span>  * @example
<span class='line'>165</span>  * var rsu = require("jsrsasign-util");
<span class='line'>166</span>  * var obj = {aaa: "bbb", "ccc": 123};
<span class='line'>167</span>  * rsu.printJSON(obj, "obj = ") &rarr;
<span class='line'>168</span>  * obj = {
<span class='line'>169</span>  *   "aaa": "bbb",
<span class='line'>170</span>  *   "ccc": 123
<span class='line'>171</span>  * }
<span class='line'>172</span>  */</span><span class="WHIT">
<span class='line'>173</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">printJSON</span><span class="PUNC">(</span><span class="NAME">json</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">prefix</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>174</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>175</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">prefix</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">prefix</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>176</span> </span><span class="WHIT">    </span><span class="NAME">console.log</span><span class="PUNC">(</span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">JSON.stringify</span><span class="PUNC">(</span><span class="NAME">json</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"  "</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>177</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>178</span> 
<span class='line'>179</span> </span></pre></body></html>